import { ref, reactive } from "vue";
import { defineStore } from 'pinia';

export const useOrgStore = defineStore('org', {
  state: () => ({
    // 当前选中的组织ID  
    selectedOrgNode: null,
    searchAll: ref(0),
    orgModel: reactive({
      id: '',
      orgName: '',
      pid: '',
      pName: '',
      orgType: null,
      addTime: null,
      addUserId: '',
      editTime: null,
      editUserId: '',
      mark: ''
    })
  }),
  actions: {
    // 更新当前选中的组织ID  
    setSelectedOrgNode(org) {
      this.selectedOrgNode = org;
    },
    resetOrgModel() {
      this.orgModel = {
        id: '',
        orgName: '',
        pid: '',
        pName: '',
        orgType: null,
        addTime: null,
        addUserId: '',
        editTime: null,
        editUserId: '',
        mark: ''
      };
    }
  },
  getters: {
    // 获取当前选中组织的名称  
    selectedOrgName: () => {

    },
  },
  //   persist: {
  //     key: 'useOrgStore', // 存储的 key
  //     storage: window.localStorage, // 使用 localStorage
  //     paths: ['selectedOrgNode'], // 需要持久化的字段
  //   }
});